Skip to content

Improve message of palette/na.value mismatch - #6767

Merged
teunbrand merged 2 commits into
tidyverse:mainfrom
teunbrand:pal_na_message
Oct 2, 2026
Merged

teunbrand merged 2 commits into
tidyverse:mainfrom
teunbrand:pal_na_message

Conversation

@teunbrand

Copy link
Copy Markdown
Collaborator

This is a spontaneous PR without a linked issue.

The current error message when using incompatible palette and na.value is confusing. It is unclear why na.value should have the character type.

library(ggplot2)

df <- mpg
df$drv[12] <- NA

ggplot(df, aes(displ, hwy, shape = drv)) +
  geom_point() +
  scale_shape_manual(
    values = c("circle small", "triangle", "square"),
    na.value = 4
  )
#> Error in `vec_slice<-`:
#> ! Can't convert `na_value` <double> to <character>.

Created on 2025-12-08 with reprex v2.1.1

In this PR, it is more clear (it should match the palette type).

#> Error in `vec_assign()` at ggplot2/R/scale-.R:1343:7:
#> ! Can't convert `na.value` <double> to match type of `palette` <character>.

@teunbrand
teunbrand requested a review from thomasp85 September 24, 2026 10:02

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand
teunbrand merged commit 0df9e62 into tidyverse:main Oct 2, 2026
13 checks passed
@teunbrand
teunbrand deleted the pal_na_message branch October 2, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants